
var app = getApp()
Page({
  data: {
    phone: '',
    polyline: [
      {
        points: [],
        color: "#00ff00",
        width: 6,
        arrowLine: true
      }
    ]
  },

  // 获取输入账号  
  phoneInput: function (e) {
    var that = this
    var phone = e.detail.value
    
    that.setData({
      phone: e.detail.value
    })
  },
  onLoad:function(options)
  {
    var that = this
    var phone = app.appData.systemUser.phone
    var id = options.id
    wx.request({
      url: app.appData.contextPath + 'findOneLatlonSetvlet',
      data: {
        phone: phone,
        id: id
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        var latlonArray = res.data;
        var polyline = that.data.polyline
        console.log(res.data)
        for (var i = 0; i < latlonArray.length && i < 2; i++) {
          polyline[0].points = latlonArray[i].locations
        }
        that.setData({
          polyline: polyline
        });
      }
    })
  },
  confirm: function () {
    var that = this;
    var phone = this.data.phone
    var points = this.data.polyline[0].points
    wx.request({
      url: app.appData.contextPath + 'messageservlet',
      data: {
        latlon: JSON.stringify(points),
        phone: phone,
        sendPhone: app.appData.systemUser.phone
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        console.info("消息发送成功" + res.data)
        wx.switchTab({
          url: "/pages/user/user",
        })
      },
      fail: function () {
        console.info("消息发送失败")
      }
    })
  }
})  